package de.reichelt.fxrequi.data;

import de.reichelt.fx.FxOption;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Requirement {
  
  private final IntegerProperty id = new SimpleIntegerProperty();
  private final StringProperty projectName = new SimpleStringProperty();
  private final IntegerProperty parentId = new SimpleIntegerProperty();
  private final StringProperty counter = new SimpleStringProperty();
  private final StringProperty title = new SimpleStringProperty();
  private final ObjectProperty<FxOption> state = new SimpleObjectProperty<>();
  private final StringProperty descr = new SimpleStringProperty();
  private final StringProperty remark = new SimpleStringProperty();
  private final ObjectProperty<ProjectVersion> projectVersion = new SimpleObjectProperty<>();
  private final ObjectProperty<Artefact> artefact = new ReadOnlyObjectWrapper<>();
  private final ObjectProperty<FxOption> priority = new SimpleObjectProperty<>();
  private final StringProperty stakeholder = new SimpleStringProperty();
  private final ObjectProperty<FxOption> stakeholderType = new SimpleObjectProperty<>();
  private final ObjectProperty<Category> category = new SimpleObjectProperty<>();
  private final BooleanProperty testRequired = new SimpleBooleanProperty();
  private final StringProperty worker = new SimpleStringProperty();
  private final ObjectProperty<FxOption> workState = new SimpleObjectProperty<>();
  private final StringProperty workComment = new SimpleStringProperty();
  private final StringProperty solution = new SimpleStringProperty();
  private final IntegerProperty costs = new SimpleIntegerProperty();
  private final StringProperty keywords = new SimpleStringProperty();
  private final ObjectProperty<Date> dateCreated = new SimpleObjectProperty<>();
  private final StringProperty userCreated = new SimpleStringProperty();
  
  public static List<FxOption> states = Arrays.asList(
          new FxOption("new", "neu"), 
          new FxOption("released", "freigegeben"), 
          new FxOption("modified", "geändert"), 
          new FxOption("done", "implementiert"), 
          new FxOption("tested", "getestet"), 
          new FxOption("failure", "fehlerhaft"));
    
  public static List<FxOption> priorities = Arrays.asList(
          new FxOption("low", "niedrig"), 
          new FxOption("middle", "mittelhoch"), 
          new FxOption("high", "hoch"));
    
  public static List<FxOption> stakeholderTypes = Arrays.asList(
          new FxOption("internal", "intern"), 
          new FxOption("customer", "Kunde"));
    
  public static List<FxOption> workStates = Arrays.asList(
          new FxOption("new", "neu"), 
          new FxOption("accepted", "übernommen"),
          new FxOption("done", "erledigt"));
    
  
  public Requirement() {
  }

  public Requirement(Integer id, String projectName, ProjectVersion version, 
          Artefact artefact, Integer parentId, String counter, String title, 
          String descr, FxOption priority, FxOption state, String stakeholder,
          FxOption stakeholderType, Category category, String remark,
          Boolean testRequired, String worker, FxOption workState, 
          String workComment, String solution, Integer costs, String keywords) {
    setId(id);
    setProjectName(projectName);
    setProjectVersion(version);
    setArtefact(artefact);
    setParentId(parentId);
    setCounter(counter);
    setTitle(title);
    setDescr(descr);
    setPriority(priority);
    setState(state);
    setStakeholder(stakeholder);
    setStakeholderType(stakeholderType);
    setCategory(category);
    setRemark(remark);
    setTestRequired(testRequired);
    setWorker(worker);
    setWorkState(workState);
    setWorkComment(workComment);
    setSolution(solution);
    setCosts(costs);
    setKeywords(keywords);
  }
  
  public String getUserCreated() {
    return userCreated.get();
  }

  public void setUserCreated(String value) {
    userCreated.set(value);
  }

  public StringProperty userCreatedProperty() {
    return userCreated;
  }

  public Date getDateCreated() {
    return dateCreated.get();
  }

  public void setDateCreated(Date value) {
    dateCreated.set(value);
  }

  public ObjectProperty dateCreatedProperty() {
    return dateCreated;
  }
  
  public String getKeywords() {
    return keywords.get();
  }

  public void setKeywords(String value) {
    keywords.set(value);
  }

  public StringProperty keywordsProperty() {
    return keywords;
  }
  
  public Integer getCosts() {
    return costs.get();
  }

  public void setCosts(Integer value) {
    costs.setValue(value);
  }

  public IntegerProperty costsProperty() {
    return costs;
  }

  public String getSolution() {
    return solution.get();
  }

  public void setSolution(String value) {
    solution.set(value);
  }

  public StringProperty solutionProperty() {
    return solution;
  }

  public String getWorkComment() {
    return workComment.get();
  }

  public void setWorkComment(String value) {
    workComment.set(value);
  }

  public StringProperty workCommentProperty() {
    return workComment;
  }

  public FxOption getWorkState() {
    return workState.get();
  }

  public void setWorkState(FxOption value) {
    workState.set(value);
  }

  public ObjectProperty workStateProperty() {
    return workState;
  }

  public String getWorker() {
    return worker.get();
  }

  public void setWorker(String value) {
    worker.set(value);
  }

  public StringProperty workerProperty() {
    return worker;
  }

  public boolean isTestRequired() {
    return testRequired.get();
  }

  public void setTestRequired(boolean value) {
    testRequired.set(value);
  }

  public BooleanProperty testRequiredProperty() {
    return testRequired;
  }

  public Category getCategory() {
    return category.get();
  }

  public void setCategory(Category value) {
    category.set(value);
  }

  public ObjectProperty categoryProperty() {
    return category;
  }

  public FxOption getStakeholderType() {
    return stakeholderType.get();
  }

  public void setStakeholderType(FxOption value) {
    stakeholderType.set(value);
  }

  public ObjectProperty stakeholderTypeProperty() {
    return stakeholderType;
  }

  public String getStakeholder() {
    return stakeholder.get();
  }

  public void setStakeholder(String value) {
    stakeholder.set(value);
  }

  public StringProperty stakeholderProperty() {
    return stakeholder;
  }

  public FxOption getPriority() {
    return priority.get();
  }

  public void setPriority(FxOption value) {
    priority.set(value);
  }

  public ObjectProperty priorityProperty() {
    return priority;
  }
  
  public Artefact getArtefact() {
    return artefact.get();
  }

  public void setArtefact(Artefact value) {
    artefact.set(value);
  }

  public ObjectProperty artefactProperty() {
    return artefact;
  }
  
  public ProjectVersion getProjectVersion() {
    return projectVersion.get();
  }

  public void setProjectVersion(ProjectVersion value) {
    projectVersion.set(value);
  }

  public ObjectProperty projectVersionProperty() {
    return projectVersion;
  }
  
  public String getCounter() {
    return counter.get();
  }

  public void setCounter(String value) {
    counter.set(value);
  }

  public StringProperty counterProperty() {
    return counter;
  }

  public int getId() {
    return id.get();
  }

  public void setId(int value) {
    id.set(value);
  }

  public IntegerProperty idProperty() {
    return id;
  }
  
  public String getProjectName() {
    return projectName.get();
  }

  public void setProjectName(String value) {
    projectName.set(value);
  }

  public StringProperty projectNameProperty() {
    return projectName;
  }
  
  public Integer getParentId() {
    return parentId.getValue();
  }

  public void setParentId(Integer value) {
    parentId.setValue(value);
  }

  public IntegerProperty parentIdProperty() {
    return parentId;
  }
  
  public String getTitle() {
    return title.get();
  }

  public void setTitle(String value) {
    title.set(value);
  }

  public StringProperty titleProperty() {
    return title;
  }
  
  public FxOption getState() {
    return state.get();
  }

  public void setState(FxOption value) {
    state.set(value);
  }

  public ObjectProperty<FxOption> stateProperty() {
    return state;
  }
  
  public String getDescr() {
    return descr.get();
  }

  public void setDescr(String value) {
    descr.set(value);
  }

  public StringProperty descrProperty() {
    return descr;
  }
  
  public String getRemark() {
    return remark.get();
  }

  public void setRemark(String value) {
    remark.set(value);
  }

  public StringProperty remarkProperty() {
    return remark;
  }
  
  @Override
  public String toString() {
    return title.get();
  }
  
  public static FxOption getState(String key) {
    for (FxOption opt: states) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getStateByValue(String value) {
    for (FxOption opt: states) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getPriority(String key) {
    for (FxOption opt: priorities) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getPriorityByValue(String value) {
    for (FxOption opt: priorities) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getStakeholderType(String key) {
    for (FxOption opt: stakeholderTypes) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getStakeholderTypeByValue(String value) {
    for (FxOption opt: stakeholderTypes) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getWorkState(String key) {
    for (FxOption opt: workStates) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getWorkStateByValue(String value) {
    for (FxOption opt: workStates) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }
  
  

}
